package com.jy.adscm.operation.cg.controller;


import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.cg.bean.CgBom;
import com.jy.adscm.operation.cg.bean.MachineProcess;
import com.jy.adscm.operation.cg.bean.PlanResult;
import com.jy.adscm.operation.cg.bean.QueryCondition;
import com.jy.adscm.operation.cg.service.MachineProcessService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-07-12
 */
@RestController
@RequestMapping("adscm/operation/cg/machineProcess")
public class MachineProcessController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    MachineProcessService machineProcessService;
    @RequestMapping("selectAll")
    public SimpleCoreResponse selectAll(@RequestBody QueryCondition queryCondition, HttpServletRequest request) throws AdscmSystemException {
          List<MachineProcess>   machineProcesses= machineProcessService.selectMachineProcess(queryCondition);
        return  new SimpleCoreResponse("200","查询成功",machineProcesses);
    }
    @RequestMapping("select")
    public SimpleCoreResponse select(@RequestBody QueryCondition queryCondition, HttpServletRequest request) throws AdscmSystemException {
        PlanResult machineProcesses= machineProcessService.selectMac(queryCondition);
        return  new SimpleCoreResponse("200","查询成功",machineProcesses);
    }
    @RequestMapping("selectList")
    public SimpleCoreResponse selectList( HttpServletRequest request) throws AdscmSystemException {
          List<MachineProcess>   machineProcesses= machineProcessService.selectList(null);
        return  new SimpleCoreResponse("200","查询成功",machineProcesses);
    }
    @RequestMapping("createCgPlan")
    public SimpleCoreResponse createCgPlan(@RequestBody QueryCondition queryCondition, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        Integer  result= machineProcessService.createCgPlan(queryCondition,token);
        return  new SimpleCoreResponse("200","查询成功",result);
    }

}

